package jpao.benchmark;

import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author soa
 */
public class GivenStopWatchMetric {

    private void checkToStringMethod(long elapsedTime, String controlString) {
        String label = "test " + elapsedTime + "ns";
        StopWatchMetric instance = new StopWatchMetric(0, elapsedTime, label);
        String expResult = label + " - " + controlString + " (0)";
        String result = instance.toString();
        assertEquals(expResult, result);
    }

    @Test
    public void whenElapsedTimeIs999NanoSecThenToStringShouldBe999ns() {
        checkToStringMethod(999, "999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs1000NanoSecThenToStringShouldBe1micros() {
        checkToStringMethod(1000, "1 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs999999NanoSecThenToStringShouldBe999micros999ns() {
        checkToStringMethod(999999, "999 µs 999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs1000000NanoSecThenToStringShouldBe1ms0micros0ns() {
        checkToStringMethod(1000000, "1 ms 0 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs9999999NanoSecThenToStringShouldBe9ms999micros999ns() {
        checkToStringMethod(9999999, "9 ms 999 µs 999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs1000000000NanoSecThenToStringShouldBe1s0ms0micros0ns() {
        checkToStringMethod(1000000000, "1 s 0 ms 0 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs59999999999NanoSecThenToStringShouldBe59s999ms999micros999ns() {
        checkToStringMethod(59999999999L, "59 s 999 ms 999 µs 999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs60000000000NanoSecThenToStringShouldBe1m0s0ms0micros0ns() {
        checkToStringMethod(60000000000L, "1 m 0 s 0 ms 0 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs3599999999999NanoSecThenToStringShouldBe59m59s999ms999micros999ns() {
        checkToStringMethod(3599999999999L, "59 m 59 s 999 ms 999 µs 999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs3600000000000NanoSecThenToStringShouldBe1h0m0s0ms0micros0ns() {
        checkToStringMethod(3600000000000L, "1 h 0 m 0 s 0 ms 0 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs86400000000000NanoSecThenToStringShouldBe23h59m59s999ms999micros999ns() {
        checkToStringMethod(86399999999999L, "23 h 59 m 59 s 999 ms 999 µs 999 ns");
    }
    
    @Test
    public void whenElapsedTimeIs86400000000000NanoSecThenToStringShouldBe1h0m0s0ms0micros0ns() {
        checkToStringMethod(86400000000000L, "1 d 0 h 0 m 0 s 0 ms 0 µs 0 ns");
    }
    
    @Test
    public void whenElapsedTimeIs86400000000010NanoSecThenToStringShouldBe1d0h0m0s0ms0micros10ns() {
        checkToStringMethod(86400000000010L, "1 d 0 h 0 m 0 s 0 ms 0 µs 10 ns");
    }
    
    @Test
    public void whenElapsedTimeIs86400000001010NanoSecThenToStringShouldBe1d0h0m0s0ms1micros10ns() {
        checkToStringMethod(86400000001010L, "1 d 0 h 0 m 0 s 0 ms 1 µs 10 ns");
    }
    

//    /**
//     * Test of getElapsedTime method, of class StopWatchMetric.
//     */
//    @Test
//    public void testGetElapsedTime() {
//        System.out.println("getElapsedTime");
//        StopWatchMetric instance = null;
//        long expResult = 0L;
//        long result = instance.getElapsedTime();
//        assertEquals(expResult, result);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
//
//    /**
//     * Test of setElapsedTime method, of class StopWatchMetric.
//     */
//    @Test
//    public void testSetElapsedTime() {
//        System.out.println("setElapsedTime");
//        long elapsedTime = 0L;
//        StopWatchMetric instance = null;
//        instance.setElapsedTime(elapsedTime);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
//
//    /**
//     * Test of getLabel method, of class StopWatchMetric.
//     */
//    @Test
//    public void testGetLabel() {
//        System.out.println("getLabel");
//        StopWatchMetric instance = null;
//        String expResult = "";
//        String result = instance.getLabel();
//        assertEquals(expResult, result);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
//
//    /**
//     * Test of setLabel method, of class StopWatchMetric.
//     */
//    @Test
//    public void testSetLabel() {
//        System.out.println("setLabel");
//        String label = "";
//        StopWatchMetric instance = null;
//        instance.setLabel(label);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
//
//    /**
//     * Test of getTime method, of class StopWatchMetric.
//     */
//    @Test
//    public void testGetTime() {
//        System.out.println("getTime");
//        StopWatchMetric instance = null;
//        long expResult = 0L;
//        long result = instance.getTime();
//        assertEquals(expResult, result);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
//
//    /**
//     * Test of setTime method, of class StopWatchMetric.
//     */
//    @Test
//    public void testSetTime() {
//        System.out.println("setTime");
//        long time = 0L;
//        StopWatchMetric instance = null;
//        instance.setTime(time);
//        // TODO review the generated test code and remove the default call to fail.
//        fail("The test case is a prototype.");
//    }
}
